//异常过滤器
import {
  HttpException,
  ExceptionFilter,
  Catch,
  ArgumentsHost,
} from '@nestjs/common';
import { Request, Response } from 'express';

@Catch(HttpException)
export class httpexception implements ExceptionFilter {
  catch(exception: HttpException, host: ArgumentsHost) {
    const type = host.getType();
    const switchToHttp = host.switchToHttp();
    const response: Response = switchToHttp.getResponse();
    const request: Request = switchToHttp.getRequest();
    const status = exception.getStatus();
    response.status(status).json({
      statusCode: status,
      timestamp: new Date().toISOString(),
      path: request.url,
    });
  }
}
